const _ = require('lodash');

module.exports = {
  schedule: {
    cron: '0 0/10 5-23 * * ?',
    type: 'worker',
    env: ['pachong'],
    // immediate: true
  },

  async task(ctx) {
    ctx.logger.info('10分钟task 开始...');

    let r2 = await ctx.service.crawlerSvc.pengpaiAll();
    let r3 = await ctx.service.crawlerSvc.guanchazheAll();
    let r5 = await ctx.service.crawlerSvc.zhihuAll();
    let r6 = await ctx.service.crawlerSvc.choutiAll();
    let r7 = await ctx.service.rssSvc.ruanyifeng();
    let r8 = await ctx.service.rssSvc.youquhome();
    let r9 = await ctx.service.rssSvc.jihewang();
    let r10 = await ctx.service.rssSvc.chulewang();

    const topics = r2
      .concat(r3)
      .concat(r5)
      .concat(r6)
      .concat(r7)
      .concat(r8)
      .concat(r9)
      .concat(r10)
    ;

    const shuffle_topics = _.shuffle(topics);

    const result = await ctx.service.topicSvc.importTopics(shuffle_topics);
    ctx.logger.info(`minute ready ${topics.length} success ${result}`);


    // 开始热搜爬取
    await ctx.service.hotsearchSvc.hotsearchAll();

    // 开始百家号新闻爬取
    // await ctx.service.crawlerSvc.baijiahaoNews();
    ctx.logger.info('10分钟task 结束...');
  }
};
